package com.hlhj.funlike_business.activity;

import android.content.Intent;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.hlhj.funlike_business.R;
import com.hlhj.funlike_business.bean.LoginBean;
import com.hlhj.funlike_business.data.SPUser;
import com.hlhj.funlike_business.presenter.LoginPresenter;
import com.hlhj.funlike_business.views.LoginView;

import org.jetbrains.annotations.NotNull;

import de.hdodenhof.circleimageview.CircleImageView;

public class LoginAty extends BaseActivity<LoginView,LoginPresenter> implements LoginView {
    private TextView tv_btn;
    private EditText ed_password,ed_useracount;
    private CircleImageView img_logo;

    @Override
    protected int getContentId() {
        return R.layout.aty_login;
    }

    @Override
    protected void initData() {

    }

    @NotNull
    @Override
    public LoginView bindView() {
        return this;
    }

    @NotNull
    @Override
    public LoginPresenter createPresenter() {
        return new LoginPresenter();
    }

    @Override
    public void initView() {
        tv_btn=findViewById(R.id.tv_btn);
        ed_password=findViewById(R.id.ed_password);
        ed_useracount=findViewById(R.id.ed_useracount);
        img_logo=findViewById(R.id.img_logo);
    }

    @Override
    public void logicStart() {
        Glide.with(this).load(R.drawable.icon_1024).into(img_logo);
    }

    @Override
    public void setListener() {
        tv_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null==ed_useracount.getText().toString()||"".equals(ed_useracount.getText().toString()) ||null==ed_password.getText().toString()||"".equals(ed_password.getText().toString()) ){
                    Toast.makeText(LoginAty.this,"请输入账号或密码",Toast.LENGTH_SHORT).show();
                }else {
                    getPresenter().LoadLoginResult(LoginAty.this,ed_useracount.getText().toString(),ed_password.getText().toString());
                }
            }
        });
    }

    @Override
    public void showLoginResult(LoginBean loginBean) {
        Toast.makeText(LoginAty.this,loginBean.getMsg().toString(),Toast.LENGTH_SHORT).show();
        SPUser.getUser(getApplication()).setToken(loginBean.getData().getToken());
        startActivity(new Intent(LoginAty.this,MainActivity.class));
        finish();
    }
}
